<script>
import outMain from "@/components/outMain.vue";
import { ElMessage, ElMessageBox } from "element-plus";
import { Fleet, FleetDel } from "@/http/api";
export default {
  components: { outMain },
  name: "",
  data() {
    return {
      tableData: [{}],
      queryData: {
        fleet_name: "",
        page: 1,
        per_page: 15,
      },
      total: 0,
    };
  },
  props: {},
  setup() {},
  methods: {
    addFn(id) {
      this.$router.push({
        path: "/flotListAdd",
        query: { id: id, page: id ? this.queryData.page : undefined },
      });
    },
    detailFn(id) {
      this.$router.push({
        path: "/flotListDetail",
        query: { id: id, page: this.queryData.page },
      });
    },
    deleteFn(row) {
      ElMessageBox.confirm("确定删除选择的船队吗?", "删除提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(async () => {
        const { data } = await FleetDel({
          shipowner_fleet_id: row.shipowner_fleet_id,
        });
        if (data.code == 1) {
          ElMessage({
            type: "success",
            message: "删除成功",
          });
          this.getData();
        }
      });
    },
    async getData() {
      const { data } = await Fleet(this.queryData);
      if (data.code == 1) {
        this.tableData = data.data.data;
        this.total = data.data.total;
      }
    },
  },
  mounted() {},
  created() {
    this.queryData.page = Number(localStorage.getItem("boot_page")) || 1;

    this.getData();
  },
};
</script>
<template>
  <outMain>
    <div class="tableCont">
      <div class="tableName flexCont">
        <div>我的船队（{{ total }}）</div>
      </div>
      <div class="tableSerch">
        <div class="serchLeft">
          <btn value="新增" @ok="addFn"></btn>
        </div>
        <div class="serchRight">
          <el-form class="flexCenter" :inline="true">
            <el-form-item>
              <el-input
                clearable
                @clear="getData"
                @keyup.enter="getData"
                v-model="queryData.fleet_name"
                placeholder="请输入想要搜索的船队"
              />
            </el-form-item>
            <btn value="搜索" @ok="getData"></btn>
          </el-form>
        </div>
      </div>
      <el-table class="tableMain" :data="tableData" stripe style="width: 100%">
        <el-table-column
          prop="fleet_name"
          show-overflow-tooltip
          label="船队名称"
        />
        <el-table-column
          prop="fleet_tpy_name"
          show-overflow-tooltip
          label="调配员"
        />
        <el-table-column
          prop="fleet_mobile"
          show-overflow-tooltip
          label="手机号"
        />
        <el-table-column
          prop="bind_c_num"
          show-overflow-tooltip
          label="绑定船舶"
        >
          <template #default="{ row }">{{ row.bind_c_num }}条</template>
        </el-table-column>
        <el-table-column
          prop="create_time"
          width="200"
          show-overflow-tooltip
          label="创建时间"
        />
        <el-table-column prop="Name" width="140" label="操作">
          <template #default="{ row }">
            <div class="tableCtrl">
              <div
                class="greenText ctrlText"
                @click="detailFn(row.shipowner_fleet_id)"
              >
                详情
              </div>
              <div
                class="blueText ctrlText"
                @click="addFn(row.shipowner_fleet_id)"
              >
                编辑
              </div>
              <div class="redText ctrlText" @click="deleteFn(row)">删除</div>
            </div>
          </template>
        </el-table-column>
      </el-table>
      <div class="pageCont">
        <el-pagination
          v-model:currentPage="queryData.page"
          v-model:page-size="queryData.per_page"
          background
          layout="total, prev, pager, next, jumper"
          :total="total"
          @size-change="getData"
          @current-change="getData"
        />
      </div>
    </div>
  </outMain>
</template>
<style scoped lang="less"></style>
